//
//  ZJMineThroughRecordInfoMoreView.m
//  ZJControlsClass
//
//  Created by wandoufo on 2024/12/16.
//

#import "ZJMineThroughRecordInfoMoreView.h"
#import "ZJMineThroughRecordInfoMoreViewTableViewCell.h"


@interface ZJMineThroughRecordInfoMoreView ()<UITableViewDelegate,UITableViewDataSource,protocolChooseMoreViewTypeDelegate>
{
    NSString * jinStr;
    NSString * goodsStr;
    NSString * errorStr;
}
@property (nonatomic,strong) UILabel * titleLabel;
@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) NSMutableArray * dataSource;
@property (nonatomic,strong) NSMutableArray * temp;
@property (nonatomic,strong) NSMutableArray * arr;


@property (nonatomic,strong) UIButton * canleBtn;
@property (nonatomic,strong) UIButton * makeSureBtn;

@end




@implementation ZJMineThroughRecordInfoMoreView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        self.dataSource = [NSMutableArray arrayWithObjects:@"进",@"出", nil];
        self.temp = [NSMutableArray arrayWithObjects:@"工具",@"货物",@"危险品", nil];
        self.arr = [NSMutableArray arrayWithObjects:@"正常",@"异常", nil];
        
        [self configUI];
        
        
    }
    return self;
}


-(void)configUI{
    
    [self addSubview: self.titleLabel];
    [self addSubview:self.tableView];
    [self addSubview:self.canleBtn];
    [self addSubview:self.makeSureBtn];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.top.equalTo(self).with.offset(40);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(10));
        make.left.equalTo(self).with.offset(ALIGN_WIDTH_PT(10));
        make.right.equalTo(self).with.offset(-ALIGN_WIDTH_PT(10));
        make.bottom.equalTo(self).with.offset(-ALIGN_HEIGHT_PT(100));
    }];
    
    [self.canleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).with.offset(ALIGN_WIDTH_PT(15));
        make.bottom.equalTo(self).with.offset(-ALIGN_HEIGHT_PT(20));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(110), ALIGN_HEIGHT_PT(45))));
    }];
    
    [self.makeSureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).with.offset(-ALIGN_WIDTH_PT(15));
        make.bottom.equalTo(self).with.offset(-ALIGN_HEIGHT_PT(20));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(110), ALIGN_HEIGHT_PT(45))));
    }];
    
}
#pragma mark -- 点击事件

-(void)responsTo_canelBtn{

    if (self.delegate && [self.delegate respondsToSelector:@selector(canleMoreView)]){
        [self.delegate canleMoreView];
    }
    
}

-(void)responsTo_makeSureBtn{
    [self responsTo_canelBtn];
    if (self.delegate && [self.delegate respondsToSelector:@selector(choosemoreView:goodsStr:errorStr:)]){
        [self.delegate choosemoreView:jinStr goodsStr:goodsStr errorStr:errorStr];
    }
    
}
#pragma mark -- protocolChooseMoreViewTypeDelegate

-(void)chooseTypeWithString:(NSString *)str{
    if ([str containsString:@"进"] || [str containsString:@"出"]){
        jinStr = str;
    }else if ([str containsString:@"工具"] || [str containsString:@"货物"] || [str containsString:@"危险品"]){
        goodsStr = str;
    }else {
        errorStr = str;
    }
}


#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZJMineThroughRecordInfoMoreViewTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ZJMineThroughRecordInfoMoreViewTableViewCell"];
    if (!cell){
        cell = [[ZJMineThroughRecordInfoMoreViewTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"ZJMineThroughRecordInfoMoreViewTableViewCell"];
    }
    cell.delegate = self;
    
    
    if (indexPath.section == 0){
        cell.dataArray = [NSMutableArray arrayWithArray:self.dataSource];
    }else if (indexPath.section == 1){
        cell.dataArray = [NSMutableArray arrayWithArray:self.temp];
    }else{
        cell.dataArray = [NSMutableArray arrayWithArray:self.arr];
    }
    
    return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return ALIGN_HEIGHT_PT(45);
}



-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 300, 45)];
    
    UILabel * headLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 290, 45)];
    headLabel.textColor = [UIColor blackColor];
    headLabel.textAlignment = NSTextAlignmentLeft;
    headLabel.font = FONT14;
    [headView addSubview:headLabel];
    
    if (section == 0){
        headLabel.text = @"通行类型";
    }else if (section == 1){
        headLabel.text = @"工具货物";
    }else{
        headLabel.text = @"通行状态";
    }
    
    
    return headView;
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 45;
}


#pragma mark -- 懒加载

-(UILabel *)titleLabel{
    if (!_titleLabel){
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:16 weight:0.3];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.text = @"更多查询";
    }
    return _titleLabel;
}

-(UITableView *)tableView{
    if (!_tableView){
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:(UITableViewStyleGrouped)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
    }
    return _tableView;
}

-(UIButton *)canleBtn{
    if (!_canleBtn) {
        _canleBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_canleBtn setTitleColor:COLOR_RGB(50, 113, 237) forState:(UIControlStateNormal)];
        _canleBtn.titleLabel.font = FONT14;
        _canleBtn.layer.cornerRadius = 5;
        [_canleBtn setTitle:@"返回" forState:(UIControlStateNormal)];
        _canleBtn.layer.masksToBounds = YES;
        _canleBtn.layer.borderColor = COLOR_RGB(50, 113, 237).CGColor;
        _canleBtn.layer.borderWidth = 1;
        [_canleBtn addTarget:self action:@selector(responsTo_canelBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _canleBtn;
}

-(UIButton *)makeSureBtn{
    if (!_makeSureBtn) {
        _makeSureBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_makeSureBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        _makeSureBtn.titleLabel.font = FONT14;
        _makeSureBtn.layer.cornerRadius = 5;
        _makeSureBtn.layer.masksToBounds = YES;
        [_makeSureBtn setTitle:@"确认" forState:(UIControlStateNormal)];
        _makeSureBtn.backgroundColor = COLOR_RGB(50, 113, 237);
        [_makeSureBtn addTarget:self action:@selector(responsTo_makeSureBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _makeSureBtn;
}



@end
